#-*- coding:gbk -*-
import os
import os.path
import MySQLdb
import timeit
import datetime
import shutil

conn= MySQLdb.connect(
        host='localhost',
        port = 3306,
        user='root',
        passwd='111qqq!',
        db ='test',
        charset='gbk'
        )
cur = conn.cursor()                                  
sqlse = "SELECT * FROM test limit 1000"
sqlsu = "UPDATE test set success = 1 where id=(%s)"
begin = datetime.datetime.now()

path = cur.execute(sqlse)

for mkdir in cur.fetchmany(path):
    
    olddir = mkdir[1]
    newdir ="d:\\test\\"+olddir[3:]   
    dirs = newdir.replace(newdir.split("\\")[-1],"")
    
    id = mkdir[2]
    if not os.path.exists(dirs):
        os.makedirs(dirs,mode=0o777)
                 
    shutil.copyfile(olddir,newdir)
    cur.execute(sqlsu,(id))
        #print olddir
        
    

end = datetime.datetime.now()

print end-begin
cur.close()
conn.commit()
conn.close()

